const app = getApp();
const Controller = require('../controllers/controllers.js').controller;
const WxParse = require('../Common/wxParse/wxParse.js');
Page({
  data: {
    key:'',
    title:'',
  },
  onLoad: function (options) {
    if(options.parentid){
      app.globalData.parentid=options.parentid
    }


    if(options.banner){
      wx.setNavigationBarTitle({
        title:'吃对了嘛'
      })
      var that = this;
      var content=wx.getStorageSync('bannerContent')
      WxParse.wxParse('content', 'html', content, that, 5);
      
    }


    if(options.key){ //  一口价购买流程
      this.setData({
        key:options.key,
        title:options.name,
      })
      wx.setNavigationBarTitle({
        title:options.name
      })
      this.appinfo()
    }
    
  },
  onShow(){

  },
  appinfo(){
    Controller.appinfo({key:this.data.key}).then(res=>{
      if(res.data.baseData){
        if(res.data.baseData.content){
          var content=res.data.baseData.content
          var that = this;
          WxParse.wxParse('content', 'html', content, that, 5);
          res.data.baseData.content = JSON.stringify(res.data.baseData.content).replace(/<img/gi, "<img class='richImg' style='width:auto!important;height:auto!important;max-height:100%;width:100%;'");
          res.data.baseData.content = JSON.parse(res.data.baseData.content);
        }
      }
    })
  },
  onShareAppMessage: function (e) {
    let title = '';
    let imageUrl = '';
    let path=app.getCurrentPageUrlWithArgs()
    let obj = {
      title,
      imageUrl,
      path,
      success: function (res) {},
      fail(err) {}
    }
    return obj
  },
  onShareTimeline: function(res){
    let title = '';
    let imageUrl = '';
    let path=app.getCurrentPageUrlWithArgs()
    let obj = {
      title,
      imageUrl,
      path,
      success: function (res) {},
      fail(err) {}
    }
    return obj
  },
})